<?php

namespace app\admin\validate;

use think\Validate;

class Room extends Validate
{
    protected $failException = true;

    /**
     * 验证规则
     */
    protected $rule = [
        'name' => 'require|unique:room,name',
        'store_id' => 'require',
    ];

    /**
     * 提示消息
     */
    protected $message = [
        'name.require' => '房间名称不能为空',
        'name.unique' => '房间名称已存在',
        'store_id.require' => '请选择一个门店',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['name', 'store_id'],
        'edit' => ['name', 'store_id'],
    ];

    /**
     * 编辑场景验证
     */
    public function sceneEdit()
    {
        return $this->only(['name', 'store_id'])
            ->append('name', 'unique:room,name,' . input('post.id') . ',id');
    }
}
